package com.tsd.jxc.stock.service.impl;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.stock.dao.JxcStockOutbillLogisticsMapper;
import com.tsd.jxc.stock.entity.JxcStockOutbillLogistics;
import com.tsd.jxc.stock.entity.JxcStockOutbillLogisticsExt;
import com.tsd.jxc.stock.service.JxcStockOutbillLogisticsService;
import com.tsd.service.BaseServiceImpl;
import com.tsd.system.entity.SysUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 描述：JxcStockOutbillLogistics 服务实现层
 *
 * @author Hillpool
 * @date 2022/07/29 15:06:33
 */
@Service
public class JxcStockOutbillLogisticsServiceImpl extends BaseServiceImpl implements JxcStockOutbillLogisticsService {

    @Resource
    private JxcStockOutbillLogisticsMapper jxcStockOutbillLogisticsMapper;

    @Override
    public JxcStockOutbillLogistics getJxcStockOutbillLogisticsById(Long id) throws Exception {
        return jxcStockOutbillLogisticsMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcStockOutbillLogisticsExt queryBySid(String sid) throws Exception {
        return jxcStockOutbillLogisticsMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcStockOutbillLogisticss(List<String> list, SysUser opUser) throws Exception {
        for (String sid : list) {
            JxcStockOutbillLogistics old = jxcStockOutbillLogisticsMapper.selectBySid(sid);
            super.checkEmpty(old, "该记录不存在");
            super.autoInjectBaseData(old, opUser, TYPE_DELETE);
            jxcStockOutbillLogisticsMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcStockOutbillLogistics(JxcStockOutbillLogistics record, SysUser opUser) throws Exception {
        if (HlpUtils.isEmpty(record.getId())) {
            super.autoInjectBaseData(record, opUser, this.TYPE_CREATE);
            jxcStockOutbillLogisticsMapper.insertSelective(record);
        } else {
            super.autoInjectBaseData(record, opUser, this.TYPE_UPDATE);
            jxcStockOutbillLogisticsMapper.updateByPrimaryKeySelective(record);
        }
    }

    @Override
    public List<JxcStockOutbillLogisticsExt> findJxcStockOutbillLogisticss(Map<String, Object> params, PageBean page) throws Exception {
        return jxcStockOutbillLogisticsMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcStockOutbillLogisticsExt> findJxcStockOutbillLogisticss(Map<String, Object> params) throws Exception {
        return jxcStockOutbillLogisticsMapper.selectByParams(params);
    }

    @Override
    public List<JxcStockOutbillLogisticsExt> getAllLogisticsByPage(Map<String, Object> params, PageBean page) throws Exception {
        return jxcStockOutbillLogisticsMapper.getAllLogisticsByPage(params, page);
    }

    @Override
    public List<JxcStockOutbillLogisticsExt> selectLogisticsByPage(Map<String, Object> params, PageBean page) throws Exception {
        return jxcStockOutbillLogisticsMapper.selectLogisticsByPage(params, page);
    }

    @Override
    public JxcStockOutbillLogisticsExt queryLogisticsByOutbillSid(String outbill_sid) throws Exception {
        JxcStockOutbillLogisticsExt params = new JxcStockOutbillLogisticsExt();
        params.setDr(0);
        params.setOutbill_sid(outbill_sid);
        List<JxcStockOutbillLogisticsExt> list = jxcStockOutbillLogisticsMapper.selectByEntity(params);
        if (!HlpUtils.isEmptyList(list)) {
            return list.get(0);
        }
        return null;
    }

}